<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简单计数器</title>

    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
        }

        .display {
            width: 100px;
            font-size: 48px;
            margin-bottom: 20px;
            padding: 10px 30px;
            border: 2px solid #333;
            border-radius: 5px;
            text-align: center;
        }

        .buttons {
            display: flex;
            gap: 10px;
        }

        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            border: none;
            border-radius: 5px;
            color: white;
        }

        .start {
            background-color: #4CAF50;
        }

        .pause {
            background-color: #FFA500;
        }

        .stop {
            background-color: #F44336;
        }

        button:hover {
            opacity: 0.8;
        }
    </style>

</head>

<body>
    <div class="display">0</div>
    <div class="buttons">
        <button class="start">开始</button>
        <button class="pause">暂停</button>
        <button class="stop">停止</button>
    </div>
</body>
<script>
    let display = document.querySelector('.display');
    let startBtn = document.querySelector('.start');
    let pauseBtn = document.querySelector('.pause');
    let stopBtn = document.querySelector('.stop');

    let count = 0;
    let timer = null;

    startBtn.addEventListener('click', function () {
        if (!timer) {
            timer = setInterval(function () {
                count++;
                display.innerHTML = count;
            }, 1000);
        }
    });


    pauseBtn.addEventListener('click', function () {
        if (timer) {
            clearInterval(timer);
            timer = null;
        }
    });


    stopBtn.addEventListener('click', function () {
        if (timer) {
            clearInterval(timer);
            timer = null;
        }
        count = 0;
        display.innerHTML = count;
    });
</script>

</html>